import { KeyCodeInfo, KeyInfo } from "../types/types"

export const basicKeyToByte = {
    KC_NO: 0x0000,
    KC_TRNS: 0x0001,
    KC_A: 0x0004,
    KC_B: 0x0005,
    KC_C: 0x0006,
    KC_D: 0x0007,
    KC_E: 0x0008,
    KC_F: 0x0009,
    KC_G: 0x000a,
    KC_H: 0x000b,
    KC_I: 0x000c,
    KC_J: 0x000d,
    KC_K: 0x000e,
    KC_L: 0x000f,
    KC_M: 0x0010,
    KC_N: 0x0011,
    KC_O: 0x0012,
    KC_P: 0x0013,
    KC_Q: 0x0014,
    KC_R: 0x0015,
    KC_S: 0x0016,
    KC_T: 0x0017,
    KC_U: 0x0018,
    KC_V: 0x0019,
    KC_W: 0x001a,
    KC_X: 0x001b,
    KC_Y: 0x001c,
    KC_Z: 0x001d,
    KC_1: 0x001e,
    KC_2: 0x001f,
    KC_3: 0x0020,
    KC_4: 0x0021,
    KC_5: 0x0022,
    KC_6: 0x0023,
    KC_7: 0x0024,
    KC_8: 0x0025,
    KC_9: 0x0026,
    KC_0: 0x0027,
    KC_ENT: 0x0028,
    KC_ESC: 0x0029,
    KC_BSPC: 0x002a,
    KC_TAB: 0x002b,
    KC_SPC: 0x002c,
    KC_MINS: 0x002d,
    KC_EQL: 0x002e,
    KC_LBRC: 0x002f,
    KC_RBRC: 0x0030,
    KC_BSLS: 0x0031,
    KC_NUHS: 0x0032,
    KC_SCLN: 0x0033,
    KC_QUOT: 0x0034,
    KC_GRV: 0x0035,
    KC_COMM: 0x0036,
    KC_DOT: 0x0037,
    KC_SLSH: 0x0038,
    KC_CAPS: 0x0039,
    KC_F1: 0x003a,
    KC_F2: 0x003b,
    KC_F3: 0x003c,
    KC_F4: 0x003d,
    KC_F5: 0x003e,
    KC_F6: 0x003f,
    KC_F7: 0x0040,
    KC_F8: 0x0041,
    KC_F9: 0x0042,
    KC_F10: 0x0043,
    KC_F11: 0x0044,
    KC_F12: 0x0045,
    KC_PSCR: 0x0046,
    KC_SLCK: 0x0047,
    KC_PAUS: 0x0048,
    KC_INS: 0x0049,
    KC_HOME: 0x004a,
    KC_PGUP: 0x004b,
    KC_DEL: 0x004c,
    KC_END: 0x004d,
    KC_PGDN: 0x004e,
    KC_RGHT: 0x004f,
    KC_LEFT: 0x0050,
    KC_DOWN: 0x0051,
    KC_UP: 0x0052,
    KC_NLCK: 0x0053,
    KC_PSLS: 0x0054,
    KC_PAST: 0x0055,
    KC_PMNS: 0x0056,
    KC_PPLS: 0x0057,
    KC_PENT: 0x0058,
    KC_P1: 0x0059,
    KC_P2: 0x005a,
    KC_P3: 0x005b,
    KC_P4: 0x005c,
    KC_P5: 0x005d,
    KC_P6: 0x005e,
    KC_P7: 0x005f,
    KC_P8: 0x0060,
    KC_P9: 0x0061,
    KC_P0: 0x0062,
    KC_PDOT: 0x0063,
    KC_NUBS: 0x0064,
    KC_APP: 0x0065,
    KC_POWER: 0x0066,
    KC_PEQL: 0x0067,
    KC_F13: 0x0068,
    KC_F14: 0x0069,
    KC_F15: 0x006a,
    KC_F16: 0x006b,
    KC_F17: 0x006c,
    KC_F18: 0x006d,
    KC_F19: 0x006e,
    KC_F20: 0x006f,
    KC_F21: 0x0070,
    KC_F22: 0x0071,
    KC_F23: 0x0072,
    KC_F24: 0x0073,
    KC_EXECUTE: 0x0074,
    KC_HELP: 0x0075,
    KC_MENU: 0x0076,
    KC_SELECT: 0x0077,
    KC_STOP: 0x0078,
    KC_AGAIN: 0x0079,
    KC_UNDO: 0x007a,
    KC_CUT: 0x007b,
    KC_COPY: 0x007c,
    KC_PASTE: 0x007d,
    KC_FIND: 0x007e,
    KC_LCAP: 0x0082,
    KC_LNUM: 0x0083,
    KC_LSCR: 0x0084,
    KC_PCMM: 0x0085,
    KC_KP_EQUAL_AS400: 0x0086,
    KC_RO: 0x0087,
    KC_KANA: 0x0088,
    KC_JYEN: 0x0089,
    KC_HENK: 0x008a,
    KC_MHEN: 0x008b,
    KC_INT6: 0x008c,
    KC_INT7: 0x008d,
    KC_INT8: 0x008e,
    KC_INT9: 0x008f,
    KC_HAEN: 0x0090,
    KC_HANJ: 0x0091,
    KC_LANG3: 0x0092,
    KC_LANG4: 0x0093,
    KC_LANG5: 0x0094,
    KC_LANG6: 0x0095,
    KC_LANG7: 0x0096,
    KC_LANG8: 0x0097,
    KC_LANG9: 0x0098,
    KC_ERAS: 0x0099,
    KC_SYSREQ: 0x009a,
    KC_CANCEL: 0x009b,
    KC_CLR: 0x009c,
    KC_CLEAR: 0x009c,
    KC_PRIOR: 0x009d,
    KC_OUT: 0x00a0,
    KC_OPER: 0x00a1,
    KC_CLEAR_AGAIN: 0x00a2,
    KC_CRSEL: 0x00a3,
    KC_EXSEL: 0x00a4,
    KC_PWR: 0x00a5,
    KC_SLEP: 0x00a6,
    KC_WAKE: 0x00a7,
    KC_MUTE: 0x00a8,
    KC_VOLU: 0x00a9,
    KC_VOLD: 0x00aa,
    KC_MNXT: 0x00ab,
    KC_MPRV: 0x00ac,
    KC_MSTP: 0x00ad,
    KC_MPLY: 0x00ae,
    KC_MSEL: 0x00af,
    KC_EJCT: 0x00b0,
    KC_MAIL: 0x00b1,
    KC_CALC: 0x00b2,
    KC_MYCM: 0x00b3,
    KC_WWW_SEARCH: 0x00b4,
    KC_WWW_HOME: 0x00b5,
    KC_WWW_BACK: 0x00b6,
    KC_WWW_FORWARD: 0x00b7,
    KC_WWW_STOP: 0x00b8,
    KC_WWW_REFRESH: 0x00b9,
    KC_WWW_FAVORITES: 0x00ba,
    KC_MFFD: 0x00bb,
    KC_MRWD: 0x00bc,
    KC_BRIU: 0x00bd,
    KC_BRID: 0x00be,
    KC_LCTL: 0x00e0,
    KC_LSFT: 0x00e1,
    KC_LALT: 0x00e2,
    KC_LGUI: 0x00e3,
    KC_RCTL: 0x00e4,
    KC_RSFT: 0x00e5,
    KC_RALT: 0x00e6,
    KC_RGUI: 0x00e7,
    KC_MS_UP: 0x00f0,
    KC_MS_DOWN: 0x00f1,
    KC_MS_LEFT: 0x00f2,
    KC_MS_RIGHT: 0x00f3,
    KC_MS_BTN1: 0x00f4,
    KC_MS_BTN2: 0x00f5,
    KC_MS_BTN3: 0x00f6,
    KC_MS_BTN4: 0x00f7,
    KC_MS_BTN5: 0x00f8,
    KC_MS_WH_UP: 0x00f9,
    KC_MS_WH_DOWN: 0x00fa,
    KC_MS_WH_LEFT: 0x00fb,
    KC_MS_WH_RIGHT: 0x00fc,
    KC_MS_ACCEL0: 0x00fd,
    KC_MS_ACCEL1: 0x00fe,
    KC_MS_ACCEL2: 0x00ff,
    RESET: 0x5c00,
    DEBUG: 0x5c01,
    MAGIC_TOGGLE_NKRO: 0x5c14,
    KC_GESC: 0x5c16,
    AU_ON: 0x5c1d,
    AU_OFF: 0x5c1e,
    AU_TOG: 0x5c1f,
    CLICKY_TOGGLE: 0x5c20,
    CLICKY_ENABLE: 0x5c21,
    CLICKY_DISABLE: 0x5c22,
    CLICKY_UP: 0x5c23,
    CLICKY_DOWN: 0x5c24,
    CLICKY_RESET: 0x5c25,
    MU_ON: 0x5c26,
    MU_OFF: 0x5c27,
    MU_TOG: 0x5c28,
    MU_MOD: 0x5c29,
    BL_ON: 0x5cbb,
    BL_OFF: 0x5cbc,
    BL_DEC: 0x5cbd,
    BL_INC: 0x5cbe,
    BL_TOGG: 0x5cbf,
    BL_STEP: 0x5cc0,
    BL_BRTG: 0x5cc1,
    RGB_TOG: 0x5cc2,
    RGB_MOD: 0x5cc3,
    RGB_RMOD: 0x5cc4,
    RGB_HUI: 0x5cc5,
    RGB_HUD: 0x5cc6,
    RGB_SAI: 0x5cc7,
    RGB_SAD: 0x5cc8,
    RGB_VAI: 0x5cc9,
    RGB_VAD: 0x5cca,
    RGB_SPI: 0x5ccb,
    RGB_SPD: 0x5ccc,
    RGB_M_P: 0x5ccd,
    RGB_M_B: 0x5cce,
    RGB_M_R: 0x5ccf,
    RGB_M_SW: 0x5cd0,
    RGB_M_SN: 0x5cd1,
    RGB_M_K: 0x5cd2,
    RGB_M_X: 0x5cd3,
    RGB_M_G: 0x5cd4,
    KC_LSPO: 0x5cd7,
    KC_RSPC: 0x5cd8,
    KC_SFTENT: 0x5cd9,
    KC_LCPO: 0x5cf3,
    KC_RCPC: 0x5cf4,
    KC_LAPO: 0x5cf5,
    KC_RAPC: 0x5cf6,
    BR_INC: 0x5f00,
    BR_DEC: 0x5f01,
    EF_INC: 0x5f02,
    EF_DEC: 0x5f03,
    ES_INC: 0x5f04,
    ES_DEC: 0x5f05,
    H1_INC: 0x5f06,
    H1_DEC: 0x5f07,
    S1_INC: 0x5f08,
    S1_DEC: 0x5f09,
    H2_INC: 0x5f0a,
    H2_DEC: 0x5f0b,
    S2_INC: 0x5f0c,
    S2_DEC: 0x5f0d,
    FN_MO13: 0x5f10,
    FN_MO23: 0x5f11,
};

const evtToKeyByte = {
    Digit1: basicKeyToByte.KC_1,
    Digit2: basicKeyToByte.KC_2,
    Digit3: basicKeyToByte.KC_3,
    Digit4: basicKeyToByte.KC_4,
    Digit5: basicKeyToByte.KC_5,
    Digit6: basicKeyToByte.KC_6,
    Digit7: basicKeyToByte.KC_7,
    Digit8: basicKeyToByte.KC_8,
    Digit9: basicKeyToByte.KC_9,
    Digit0: basicKeyToByte.KC_0,
    KeyA: basicKeyToByte.KC_A,
    KeyB: basicKeyToByte.KC_B,
    KeyC: basicKeyToByte.KC_C,
    KeyD: basicKeyToByte.KC_D,
    KeyE: basicKeyToByte.KC_E,
    KeyF: basicKeyToByte.KC_F,
    KeyG: basicKeyToByte.KC_G,
    KeyH: basicKeyToByte.KC_H,
    KeyI: basicKeyToByte.KC_I,
    KeyJ: basicKeyToByte.KC_J,
    KeyK: basicKeyToByte.KC_K,
    KeyL: basicKeyToByte.KC_L,
    KeyM: basicKeyToByte.KC_M,
    KeyN: basicKeyToByte.KC_N,
    KeyO: basicKeyToByte.KC_O,
    KeyP: basicKeyToByte.KC_P,
    KeyQ: basicKeyToByte.KC_Q,
    KeyR: basicKeyToByte.KC_R,
    KeyS: basicKeyToByte.KC_S,
    KeyT: basicKeyToByte.KC_T,
    KeyU: basicKeyToByte.KC_U,
    KeyV: basicKeyToByte.KC_V,
    KeyW: basicKeyToByte.KC_W,
    KeyX: basicKeyToByte.KC_X,
    KeyY: basicKeyToByte.KC_Y,
    KeyZ: basicKeyToByte.KC_Z,
    Comma: basicKeyToByte.KC_COMM,
    Period: basicKeyToByte.KC_DOT,
    Semicolon: basicKeyToByte.KC_SCLN,
    Quote: basicKeyToByte.KC_QUOT,
    BracketLeft: basicKeyToByte.KC_LBRC,
    BracketRight: basicKeyToByte.KC_RBRC,
    Backspace: basicKeyToByte.KC_BSPC,
    Backquote: basicKeyToByte.KC_GRV,
    Slash: basicKeyToByte.KC_SLSH,
    Backslash: basicKeyToByte.KC_BSLS,
    Minus: basicKeyToByte.KC_MINS,
    Equal: basicKeyToByte.KC_EQL,
    IntlRo: basicKeyToByte.KC_RO,
    IntlYen: basicKeyToByte.KC_JYEN,
    AltLeft: basicKeyToByte.KC_LALT,
    AltRight: basicKeyToByte.KC_RALT,
    CapsLock: basicKeyToByte.KC_CAPS,
    ControlLeft: basicKeyToByte.KC_LCTL,
    ControlRight: basicKeyToByte.KC_RCTL,
    MetaLeft: basicKeyToByte.KC_LGUI,
    MetaRight: basicKeyToByte.KC_RGUI,
    OSLeft: basicKeyToByte.KC_LGUI,
    OSRight: basicKeyToByte.KC_RGUI,
    ShiftLeft: basicKeyToByte.KC_LSFT,
    ShiftRight: basicKeyToByte.KC_RSFT,
    ContextMenu: basicKeyToByte.KC_APP,
    Enter: basicKeyToByte.KC_ENT,
    Space: basicKeyToByte.KC_SPC,
    Tab: basicKeyToByte.KC_TAB,
    Delete: basicKeyToByte.KC_DEL,
    End: basicKeyToByte.KC_END,
    Help: basicKeyToByte.KC_HELP,
    Home: basicKeyToByte.KC_HOME,
    Insert: basicKeyToByte.KC_INS,
    PageDown: basicKeyToByte.KC_PGDN,
    PageUp: basicKeyToByte.KC_PGUP,
    ArrowDown: basicKeyToByte.KC_DOWN,
    ArrowLeft: basicKeyToByte.KC_LEFT,
    ArrowRight: basicKeyToByte.KC_RGHT,
    ArrowUp: basicKeyToByte.KC_UP,
    Escape: basicKeyToByte.KC_ESC,
    PrintScreen: basicKeyToByte.KC_PSCR,
    ScrollLock: basicKeyToByte.KC_SLCK,
    AudioVolumeUp: basicKeyToByte.KC_VOLU,
    AudioVolumeDown: basicKeyToByte.KC_VOLD,
    AudioVolumeMute: basicKeyToByte.KC_MUTE,
    Pause: basicKeyToByte.KC_PAUS,
    F1: basicKeyToByte.KC_F1,
    F2: basicKeyToByte.KC_F2,
    F3: basicKeyToByte.KC_F3,
    F4: basicKeyToByte.KC_F4,
    F5: basicKeyToByte.KC_F5,
    F6: basicKeyToByte.KC_F6,
    F7: basicKeyToByte.KC_F7,
    F8: basicKeyToByte.KC_F8,
    F9: basicKeyToByte.KC_F9,
    F10: basicKeyToByte.KC_F10,
    F11: basicKeyToByte.KC_F11,
    F12: basicKeyToByte.KC_F12,
    F13: basicKeyToByte.KC_F13,
    F14: basicKeyToByte.KC_F14,
    F15: basicKeyToByte.KC_F15,
    F16: basicKeyToByte.KC_F16,
    F17: basicKeyToByte.KC_F17,
    F18: basicKeyToByte.KC_F18,
    F19: basicKeyToByte.KC_F19,
    F20: basicKeyToByte.KC_F20,
    F21: basicKeyToByte.KC_F21,
    F22: basicKeyToByte.KC_F22,
    F23: basicKeyToByte.KC_F23,
    F24: basicKeyToByte.KC_F24,
    NumLock: basicKeyToByte.KC_NLCK,
    Numpad0: basicKeyToByte.KC_P0,
    Numpad1: basicKeyToByte.KC_P1,
    Numpad2: basicKeyToByte.KC_P2,
    Numpad3: basicKeyToByte.KC_P3,
    Numpad4: basicKeyToByte.KC_P4,
    Numpad5: basicKeyToByte.KC_P5,
    Numpad6: basicKeyToByte.KC_P6,
    Numpad7: basicKeyToByte.KC_P7,
    Numpad8: basicKeyToByte.KC_P8,
    Numpad9: basicKeyToByte.KC_P9,
    NumpadAdd: basicKeyToByte.KC_PPLS,
    NumpadComma: basicKeyToByte.KC_COMM,
    NumpadDecimal: basicKeyToByte.KC_PDOT,
    NumpadDivide: basicKeyToByte.KC_PSLS,
    NumpadEnter: basicKeyToByte.KC_PENT,
    NumpadEqual: basicKeyToByte.KC_PEQL,
    NumpadMultiply: basicKeyToByte.KC_PAST,
    NumpadSubtract: basicKeyToByte.KC_PMNS,
};

const keyCodes = [
    {code: 0x0004, key: 'A'},
    {code: 0x0005, key: 'B'},
    {code: 0x0006, key: 'C'},
    {code: 0x0007, key: 'D'},
    {code: 0x0008, key: 'E'},
    {code: 0x0009, key: 'F'},
    {code: 0x000a, key: 'G'},
    {code: 0x000b, key: 'H'},
    {code: 0x000c, key: 'I'},
    {code: 0x000d, key: 'J'},
    {code: 0x000e, key: 'K'},
    {code: 0x000f, key: 'L'},
    {code: 0x0010, key: 'M'},
    {code: 0x0011, key: 'N'},
    {code: 0x0012, key: 'O'},
    {code: 0x0013, key: 'P'},
    {code: 0x0014, key: 'Q'},
    {code: 0x0015, key: 'R'},
    {code: 0x0016, key: 'S'},
    {code: 0x0017, key: 'T'},
    {code: 0x0018, key: 'U'},
    {code: 0x0019, key: 'V'},
    {code: 0x001a, key: 'W'},
    {code: 0x001b, key: 'X'},
    {code: 0x001c, key: 'Y'},
    {code: 0x001d, key: 'Z'},
    {code: 0x001e, key: '1'},
    {code: 0x001f, key: '2'},
    {code: 0x0020, key: '3'},
    {code: 0x0021, key: '4'},
    {code: 0x0022, key: '5'},
    {code: 0x0023, key: '6'},
    {code: 0x0024, key: '7'},
    {code: 0x0025, key: '8'},
    {code: 0x0026, key: '9'},
    {code: 0x0027, key: '0'},
    {code: 0x0028, key: 'Return'},
    {code: 0x0029, key: 'Esc'},
    {code: 0x002A, key: 'Backspace'},
    {code: 0x002B, key: 'Tab'},
    {code: 0x002C, key: 'Space'},
    {code: 0x002D, key: '-\n_'},
    {code: 0x002E, key: '=\n+'},
    {code: 0x002F, key: '[\n{'},
    {code: 0x0030, key: ']\n}'},
    {code: 0x0031, key: '\\\n|'},
    {code: 0x0032, key: ' '},
    {code: 0x0033, key: ';\n:'},
    {code: 0x0034, key: '\'\n\"'},
    {code: 0x0035, key: '`\n~'},
    {code: 0x0036, key: ',\n<'},
    {code: 0x0037, key: '.\n>'},
    {code: 0x0038, key: '/\n?'},
    {code: 0x0039, key: 'Caps Lock'},
    {code: 0x003a, key: 'F1'},
    {code: 0x003b, key: 'F2'},
    {code: 0x003c, key: 'F3'},
    {code: 0x003d, key: 'F4'},
    {code: 0x003e, key: 'F5'},
    {code: 0x003f, key: 'F6'},
    {code: 0x0040, key: 'F7'},
    {code: 0x0041, key: 'F8'},
    {code: 0x0042, key: 'F9'},
    {code: 0x0043, key: 'F10'},
    {code: 0x0044, key: 'F11'},
    {code: 0x0045, key: 'F12'},
    {code: 0x0053, key: 'Num Lock'},
    {code: 0x0054, key: 'Num /'},
    {code: 0x0055, key: 'Num *'},
    {code: 0x0056, key: 'Num -'},
    {code: 0x0057, key: 'Num +'},
    {code: 0x0059, key: 'Num 1'},
    {code: 0x005a, key: 'Num 2'},
    {code: 0x005b, key: 'Num 3'},
    {code: 0x005c, key: 'Num 4'},
    {code: 0x005d, key: 'Num 5'},
    {code: 0x005e, key: 'Num 6'},
    {code: 0x005f, key: 'Num 7'},
    {code: 0x0060, key: 'Num 8'},
    {code: 0x0061, key: 'Num 9'},
    {code: 0x0062, key: 'Num 0'},
    {code: 0x0063, key: 'Num .'},
    {code: 0x0058, key: 'Num Enter'},
];


export function eventCode2Keycode(code: string) {
    return evtToKeyByte[code as keyof typeof evtToKeyByte];
}